#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>

#include <signal.h>   // for signal and time 
#include <time.h>
#include <sys/time.h>

#include <fcntl.h>

static int greenLed_fd;

/*
 *@brief :timer alarm service routine.
 *@ret 	 :none 
 *
 */
void* led_display(void)
{
	static int light_cnt = 0;
	
	if(light_cnt == 0x0){
		ioctl(greenLed_fd,light_cnt,0);
		light_cnt++;
	}else{
		ioctl(greenLed_fd,light_cnt,0);
		light_cnt--;
	}
}

/*
 *@brief : led green(System running status LED).
 *@ret	: none
 *
 */
int main(int argc,char **argv)
{
	struct itimerval led_time,ovaltime;   		 // Time struct used to generate alarm 

	greenLed_fd = open("/dev/led",O_RDWR);
	if(greenLed_fd < 0){
		exit(1);
	}else{
		printf("\n open led ok!\n");
	}

	led_time.it_interval.tv_sec = 1;
	led_time.it_interval.tv_usec = 0;
	led_time.it_value.tv_sec = 1;
	led_time.it_value.tv_usec = 0;       					// net poll 3s/per
	signal(SIGALRM,(void *)led_display);
	setitimer(ITIMER_REAL,&led_time,&ovaltime);	

	for(;;);

	close(greenLed_fd);
	return 0;
}

